/**
 * 
 */
package com.lehecai.ucenter.entity.permission;

import java.util.Date;

import net.sf.json.JSONObject;

import com.lehecai.core.EnabledStatus;
import com.lehecai.core.YesNoStatus;
import com.lehecai.core.type.ucenter.EducationDegreeType;
import com.lehecai.core.type.ucenter.MaritalStatus;
import com.lehecai.core.type.ucenter.SexType;
import com.lehecai.core.util.CoreDateUtils;
import com.lehecai.ucenter.entity.BaseEntity;

/**
 * @author qatang
 *
 */
public class User extends BaseEntity {
	private static final long serialVersionUID = 8224336497730392948L;
	public static final String USER_NAME_PROPERTY_NAME = "username";
	public static final String PASSWORD_PROPERTY_NAME = "password";
	public static final String NAME_PROPERTY_NAME = "name";
	public static final String ENABLED_PROPERTY_NAME = "enabled";

	private String username;
	private String password;
	private String opPwd;//二次认证密码
	private String name;
	private Date birthday;
	private Integer age;
	private SexType sex;
	private String nation;//民族
	private Date entryDate;//入职时间
	private Date leaveDate;//离职时间
	private Date contractBeginDate;//合同签订时间
	private Date contractEndDate;//合同到期时间
	private Date regularizationDate;//转正时间
	private EducationDegreeType educationDegree;//文化程度
	private String university;//毕业院校
	private MaritalStatus maritalStatus;//婚姻状况
	private String mobile;
	private String tel;
	private String email;
	private String qq;
	private String weibo;
	private Date createdTime;
	private Date updatedTime;
	private EnabledStatus enabled;
	private String picPath;
	private String memo;
	
	private Date loginTime;
	private Date lastLoginTime;
	//private List<Role> roles;
	//private List<App> apps;
	
    private YesNoStatus otp;//是否启用动态密码
    private String secretKey;
    private String clientIp;
    private String resourceIp;

    private String roleName;
	
	public static JSONObject convertFromObject(User user) {
		if (user == null) {
			return null;
		}
		JSONObject obj = new JSONObject();
		obj.put("uid", user.getId());
		obj.put("username", user.getUsername());
		obj.put("opPwd", user.getOpPwd());
		obj.put("name", user.getName());
		obj.put("mobile", user.getMobile());
		obj.put("tel", user.getTel());
		obj.put("email", user.getEmail());
		obj.put("birthday", user.getBirthday() == null ? null : CoreDateUtils.formatDate(user.getBirthday()));
		obj.put("age", user.getAge());
		obj.put("sex", user.getSex().getValue());
		obj.put("nation", user.getNation());
		obj.put("entry_date", user.getEntryDate() == null ? null : CoreDateUtils.formatDate(user.getEntryDate()));
		obj.put("leave_date", user.getLeaveDate() == null ? null : CoreDateUtils.formatDate(user.getLeaveDate()));
		obj.put("contract_begin_date", user.getContractBeginDate() == null ? null : CoreDateUtils.formatDate(user.getContractBeginDate()));
		obj.put("contract_end_date", user.getContractEndDate() == null ? null : CoreDateUtils.formatDate(user.getContractEndDate()));
		obj.put("regularization_date", user.getRegularizationDate() == null ? null : CoreDateUtils.formatDate(user.getRegularizationDate()));
		obj.put("education_degree", user.getEducationDegree().getValue());
		obj.put("university", user.getUniversity());
		obj.put("marital_status", user.getMaritalStatus().getValue());
		obj.put("qq", user.getQq());
		obj.put("weibo", user.getWeibo());
		obj.put("updated_time", user.getUpdatedTime() == null ? null : CoreDateUtils.formatDateTime(user.getUpdatedTime()));
		obj.put("pic_path", user.getPicPath());
		obj.put("memo", user.getMemo());
		return obj;
	}
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Date getCreatedTime() {
		if (createdTime == null) {
			createdTime = new Date();
		}
		return createdTime;
	}
	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}
	public Date getUpdatedTime() {
		return updatedTime;
	}
	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}
	public EnabledStatus getEnabled() {
		return enabled;
	}
	public void setEnabled(EnabledStatus enabled) {
		this.enabled = enabled;
	}
	public String getMemo() {
		return memo;
	}
	public void setMemo(String memo) {
		this.memo = memo;
	}
	public String getOpPwd() {
		return opPwd;
	}
	public void setOpPwd(String opPwd) {
		this.opPwd = opPwd;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public SexType getSex() {
		return sex;
	}

	public void setSex(SexType sex) {
		this.sex = sex;
	}

	public String getNation() {
		return nation;
	}

	public void setNation(String nation) {
		this.nation = nation;
	}

	public Date getEntryDate() {
		return entryDate;
	}

	public void setEntryDate(Date entryDate) {
		this.entryDate = entryDate;
	}

	public EducationDegreeType getEducationDegree() {
		return educationDegree;
	}

	public void setEducationDegree(EducationDegreeType educationDegree) {
		this.educationDegree = educationDegree;
	}

	public MaritalStatus getMaritalStatus() {
		return maritalStatus;
	}

	public void setMaritalStatus(MaritalStatus maritalStatus) {
		this.maritalStatus = maritalStatus;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getWeibo() {
		return weibo;
	}

	public void setWeibo(String weibo) {
		this.weibo = weibo;
	}

	public String getUniversity() {
		return university;
	}

	public void setUniversity(String university) {
		this.university = university;
	}

	public String getPicPath() {
		return picPath;
	}

	public void setPicPath(String picPath) {
		this.picPath = picPath;
	}

	public Date getLeaveDate() {
		return leaveDate;
	}

	public void setLeaveDate(Date leaveDate) {
		this.leaveDate = leaveDate;
	}

	public Date getContractBeginDate() {
		return contractBeginDate;
	}

	public void setContractBeginDate(Date contractBeginDate) {
		this.contractBeginDate = contractBeginDate;
	}

	public Date getContractEndDate() {
		return contractEndDate;
	}

	public void setContractEndDate(Date contractEndDate) {
		this.contractEndDate = contractEndDate;
	}

	public Date getRegularizationDate() {
		return regularizationDate;
	}

	public void setRegularizationDate(Date regularizationDate) {
		this.regularizationDate = regularizationDate;
	}

/*	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}*/

/*	public List<App> getApps() {
		return apps;
	}

	public void setApps(List<App> apps) {
		this.apps = apps;
	}*/

	public Date getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}

	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	public YesNoStatus getOtp() {
		return otp;
	}

	public void setOtp(YesNoStatus otp) {
		this.otp = otp;
	}

	public String getSecretKey() {
		return secretKey;
	}

	public void setSecretKey(String secretKey) {
		this.secretKey = secretKey;
	}

	public String getClientIp() {
		return clientIp;
	}

	public void setClientIp(String clientIp) {
		this.clientIp = clientIp;
	}

	public String getResourceIp() {
		return resourceIp;
	}

	public void setResourceIp(String resourceIp) {
		this.resourceIp = resourceIp;
	}

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }
}
